<?php

namespace App\Jobs\System;

use App\Models\WxChat;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;

class ChatExpandTypeCheckJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // todo:
        WxChat::where('refer_id', '>', 0) // 筛选refer_id大于0的行
        ->update([
            'expand_type' => 1, // 将expand_type设置为1
            'expand_id' => DB::raw('refer_id') // 使用refer_id的值来更新expand_id
        ]);

        WxChat::where('contact_apply_id', '>', 0) // 筛选contact_apply_id大于0的行
        ->update([
            'expand_type' => 2, // 将expand_type设置为2
            'expand_id' => DB::raw('contact_apply_id') // 使用refer_id的值来更新expand_id
        ]);

        WxChat::where('adoption_apply_id', '>', 0) // 筛选adoption_apply_id大于0的行
        ->update([
            'expand_type' => 3, // 将expand_type设置为3
            'expand_id' => DB::raw('adoption_apply_id') // 使用refer_id的值来更新expand_id
        ]);
    }
}
